public class Base extends Structure {
	public boolean produceReady;
	public boolean healReady;

	public Base(int _id, Player player) {
		super(_id, player);
		this.type = 10;
		this.player = player;
		this.offensive = 20;
		this.defensive = 20;
		this.armor = 10;
		this.production = 1000;
		this.health = 1000;

	}
	
	//Heals unit using _id
	public void healUnit(int _id)
	{
		this.player.getUnit(_id).incHealth();
		this.mode="STANDBY";
	}
	
	//calculates the number of ticks needed to heal a unit
	//depending on its percentageDamage and type and adds
	//the command to the command queue
	public void doHealUnit(Unit u) {
	
		
		if(u != null)
		{
			
	
		
			int maxHealth = u.getMaxHealth();
			int currentHealth = u.getHealth();
			double percentageDamage = currentHealth/maxHealth;
			int ticks=0;
			if (u.getType() == 0) // explorer
				ticks=(int)(percentageDamage * 20);
			else if (u.getType() == 1) // colonist
				ticks=(int)(percentageDamage * 30);
			else if (u.getType() == 2)// melee
				ticks=(int)(percentageDamage * 40);
			else if (u.getType() == 3)// range
				ticks=(int)(percentageDamage * 50);
			int[] command ={5,ticks,u.getStatus()[0]};
			
			this.addCommand(command);
		
		
		}
	}
	
	//creates a unit depending on _type
	//puts new unit on top of base
	public void createUnit( Map m, int _type) {
		this.mode = "STANDBY";
		if (_type == 1)

			this.player.makeExplorer(m.getTile(this.x, this.y));

		else if (_type == 2)

			this.player.makeColonist(m.getTile(this.x, this.y));

		else if (_type == 3)

			this.player.makeMelee(m.getTile(this.x, this.y));

		else if (_type == 4)

			this.player.makeRange(m.getTile(this.x, this.y));

	}
	
	//add command to command queue for this base
	public void addCommand(int[] command) {
		commandQueue.put(command);
	}

	
	public String getCommandTxt() {
		if (commandQueue.getSize() > 0) {
			int[] command;
			command = commandQueue.peek();
			switch (command[0]) {
			case 1:
				return "Creating explorer in " + command[1];
			case 2:
				return "Creating colonist in " + command[1];
			case 3:
				return "Creating Melee in " + command[1];
			case 4:
				return "Creating Range in " + command[1];
			case 5:
			return "Healing unit " + command[2];
				
			default:
				return "Idle";
			}
		} else {
			return "Idle";
		}
	}
	
	//looks at number of ticks before it calls a command
	public void getCommand(Map m) {
		int[] command;
		// System.out.println("getting command");
		if (commandQueue.getSize() > 0) {
			command = commandQueue.peek();
			if (command[0] == 1) {
				this.mode = "CREATING EXPLORER";
			} else if (command[0] == 2) {
				this.mode = "CREATING COLONIST";
			} else if (command[0] == 3) {
				this.mode = "CREATING MELEE";
			} else if (command[0] == 4) {
				this.mode = "CREATING RANGE";
			}
			else if (command[0] == 5) {
				this.mode = "HEALING";
				}
			
			if (command[1] != 0) {	//number of clicks is not zero yet, decrement
				command[1]--;
			} else {
				commandQueue.pop();
				
				if(command[0]==5)
				{
					healUnit(command[2]);
				}
				else
				{
				createUnit(m, command[0]);
				}
			}

		}
	}
	
	public void doCreate(Map m) {

		if (this.powerDelay > 0) {
			if (this.mode != "SLEEP") {
				this.powerDelay--;
				if (this.powerDelay == 0) {
					this.mode = "STANDBY";
				}
			}
		} else {
			getCommand(m);
		}
	}

	//commands to display on status viewport
	public String[] gettxtCommands() {
		String[] commands = { "Attack", "Defend", "Make", "   Explorer",
				"   Colonist", "   Melee", "   Range", "Heal", "Decommission",
				"Power down", "Power up", "Cancel orders" };
		return commands;
	}
}
